/**
 * Created by yangzhao.lyz on 17/4/17.
 */

const { transform } = require('babel-core');
const { resolve } = require('../resolve');
const CommonJsLoader = require('./CommonJsLoader');
const detective = require('detective');
const Path = require('path');

function JsLoader(module, opt, overriderContent) {
    var result = transform(overriderContent || module.file.contents, opt.babel);
    var found = detective.find(result.code);
    for (var dep of found.strings) {
        //首先找出依赖
        let loc = resolve(Path.dirname(module.file.path), dep, opt);
        module.dependency[dep] = loc;
    }
    module.code = result.code;

    return CommonJsLoader(module, opt);
}
module.exports = JsLoader;
